package com.yang.designmode.ActionMode.chainResponsibility.linkList;

/**
 * 责任链
 */
public class HandlerChain {
    private Handler head = null;
    private Handler tail = null;

    public void addHandler(Handler handler){
        handler.setSuccessor(null);
        if(head == null){
            head = handler;
            tail = handler;
        }else{
            tail.setSuccessor(handler);
            tail = handler;
        }
    }

    /**
     * 执行链路执行
     */
    public void handle(){
        if(head != null){
            head.handle();
        }
    }
}
